package com.citycloud.ccuap.tc.common.page;

import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("后端接口统一返回翻页对象")
public class CommonPager<T> {
	@ApiModelProperty("返回页面参数数据")
	private CommonPager<T>.PageParams page;
	@ApiModelProperty("返回数据")
	private List<T> dataList;

	public void setPage(CommonPager<T>.PageParams page) {
		this.page = page;
	}

	public void setDataList(List<T> dataList) {
		this.dataList = dataList;
	}

	@Override
    public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if (!(o instanceof CommonPager)) {
			return false;
		}
		CommonPager<?> other = (CommonPager) o;
		if (!other.canEqual(this)) {
			return false;
		}
		Object thisPage = getPage();
		Object otherPage = other.getPage();
		if (thisPage == null ? otherPage != null : !thisPage.equals(otherPage)) {
			return false;
		}
		Object thisDataList = getDataList();
		Object otherDataList = other.getDataList();
		return thisDataList == null ? otherDataList == null : thisDataList.equals(otherDataList);
	}

	protected boolean canEqual(Object other) {
		return other instanceof CommonPager;
	}

	@Override
    public int hashCode() {
		int prime = 59;
		int result = 1;
		Object thisPage = getPage();
		result = result * 59 + (thisPage == null ? 43 : thisPage.hashCode());
		Object thisDataList = getDataList();
		result = result * 59 + (thisDataList == null ? 43 : thisDataList.hashCode());
		return result;
	}

	@Override
    public String toString() {
		return "CommonPager(page=" + getPage() + ", dataList=" + getDataList() + ")";
	}

	@ApiModel("页面参数对象")
	class PageParams {
		@ApiModelProperty("当前页")
		private int currentPage;
		@ApiModelProperty("每页数量")
		private int pageSize;
		@ApiModelProperty("总条目数量")
		private int totalCount;

		public void setCurrentPage(int currentPage) {
			this.currentPage = currentPage;
		}

		public void setPageSize(int pageSize) {
			this.pageSize = pageSize;
		}

		public void setTotalCount(int totalCount) {
			this.totalCount = totalCount;
		}

		@Override
        public boolean equals(Object o) {
			if (o == this) {
				return true;
			}
			PageParams other = (PageParams) o;
			if (getCurrentPage() != other.getCurrentPage()) {
				return false;
			}
			if (getPageSize() != other.getPageSize()) {
				return false;
			}
			return getTotalCount() == other.getTotalCount();
		}

		@Override
        public int hashCode() {
			int prime = 59;
			int result = 1;
			result = result * 59 + getCurrentPage();
			result = result * 59 + getPageSize();
			result = result * 59 + getTotalCount();
			return result;
		}

		@Override
        public String toString() {
			return "CommonPager.PageParams(currentPage=" + getCurrentPage() + ", pageSize=" + getPageSize()
					+ ", totalCount=" + getTotalCount() + ")";
		}

		public int getCurrentPage() {
			return this.currentPage;
		}

		public int getPageSize() {
			return this.pageSize;
		}

		public int getTotalCount() {
			return this.totalCount;
		}

		public PageParams(int currentPage, int pageSize) {
			this.currentPage = currentPage;
			this.pageSize = pageSize;
		}
	}

	public CommonPager<T>.PageParams getPage() {
		return this.page;
	}

	public List<T> getDataList() {
		return this.dataList;
	}

	public void setTotalCount(int totalCount) {
		this.page.setTotalCount(totalCount);
	}

	public int getTotalCount() {
		return this.page.getTotalCount();
	}

	public CommonPager(PageParameter pageParameter) {
		this.page = new PageParams(pageParameter.getStart(), pageParameter.getLimit());
	}

	public CommonPager(PageParameter pageParameter, int totalCount) {
		this.page = new PageParams(pageParameter.getStart(), pageParameter.getLimit());
		this.page.setTotalCount(totalCount);
	}

	public CommonPager(PageParameter pageParameter, int totalCount, List<T> dataList) {
		this.page = new PageParams(pageParameter.getStart(), pageParameter.getLimit());
		this.page.setTotalCount(totalCount);
		this.dataList = dataList;
	}
}
